package com.dorm.cj.thread;

public class MyThread2 {
    public static void main(String[] args) throws InterruptedException {

        Thread thread2 = new Thread(() -> {

            Thread thread = new Thread(() -> {
                try {
                    Thread.sleep(3000L);
                    System.out.println("thread1-1========================");
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }, "thread1-1");
            System.out.println("thread1-1 start!");
            thread.start();


            System.out.println("threadState:" + thread.getState());
            try {
                System.out.println("thread1-1 join!");
                /*thread2等待thread1运行完再运行*/
//                thread.join();

                while (thread.isAlive()) {
                    System.out.println("thread.wait start");
                    synchronized (thread) {  //thread.wait调用如果不是在
                        thread.wait(0);
                    }
                    System.out.println("thread.waited");
                }

                System.out.println("threadState:" + thread.getState());
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println("threadState:" + thread.getState());
            System.out.println("thread2-2========================");
        }, "thread2-2");
        thread2.start();
        System.out.println("thread2State:" + thread2.getState());
    }
}
/*
main->thread2|main中thread2.start()以下的代码->thread2 run()->thread1 start()->thread.join()->thread1 run()->thread2 run()
*/